{include file="common:header" /}
{include file="common:side" /}
    <div id="page-wrapper">
      <!-- 舆情日报 -->
      <!--*************************** content部分开始 ******************-->
      <div class="container-fluid" id="m_main">
        <div class="row m-t-20">
          <div class="col-sm-12">
            <div class="white-box">
              <h2 class="box-title m-b-20">编辑教师信息</h2>
              <div class="row">
                <div class="col-sm-4">
                  <div class="form-group">
                    <label class="control-label">教师名称</label>
                    <input type="text" class="form-control" placeholder="" v-model="teacher.name">
                  </div>
                </div>
                <div class="col-sm-4">
                  <div class="form-group">
                    <label class="control-label">教师职称：</label>
                    <input type="text" class="form-control" placeholder="" v-model="teacher.title">
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="col-sm-4">
                  <div class="form-group">
                    <label class="control-label">联系方式：</label>
                    <input type="text" class="form-control" placeholder="" v-model="teacher.tel">
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="col-sm-4">
                  <div class="form-group">
                    <label class="control-label">排序号：</label>
                    <input type="text" class="form-control" placeholder="" v-model="teacher.ordernum">
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="col-sm-4">
                  <div class="form-group m-addsku-pics">
                    <label class="control-label">教师头像：(224px*224px)</label>
                    <div>
                      <label for="add_teacher_info_pic" class="btn btn-primary waves-effect waves-light" style="line-height: 20px;padding: 6px 10px">添加图片</label>
                      <input type="file" id="add_teacher_info_pic" name="file" class="addpics" data-amount="1"/>
                      <div class="col-md-12">
                        <div id="teacher_info_pic_box" class="pic-box"></div>
                        <input type="hidden" name="teacher_info_pic" class="add-pic" id="teacher_info_pic" value="" data-id="1">
                        <input type="hidden" name="delete_teacher_info_pic" class="delete-pic" id="delete_teacher_info_pic">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="col-sm-8">
                  <div class="form-group">
                    <label class="control-label">教师简介：</label>
                    <!-- 加载编辑器的容器 -->
	                  <script id="contents-box" name="content" type="text/plain"></script>
                  </div>
                </div>
              </div>
              <div class="row m-t-40">
                <div class="col-sm-8 ta-c">
                  <button type="button" name="" class="btn btn-outline btn-primary m-r-40" @click="doSubmit()">提交</button>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- /.row -->
      </div>
      <!--*************************** content部分结束 ******************-->

      <!-- <footer class="footer text-center"> 2017 &copy; Ample Admin brought to you by themedesigner.in </footer> -->
    </div>
  {include file="common:js" /}
  {include file="common:footer" /}
  <script type="text/javascript" src="/web/uedit/ueditor.config.js"></script>
  <script type="text/javascript" src="/web/uedit/ueditor.all.js"></script>
  <script src="/assets/plugins/bower_components/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>
  <script src="/assets/plugins/bower_components/jQuery-File-Upload/js/jquery.iframe-transport.js"></script>
  <script src="/assets/plugins/bower_components/jQuery-File-Upload/js/jquery.fileupload.js"></script>
  <script src="/web/js/edit.js"></script>
  <script>
    $(function() {
  		upload_photo('#add_teacher_info_pic','/dboard/upload/avatar_upload');
  	});
  </script>

  <script type="text/javascript">
    var vm = new Vue({
      el: '#m_main',
      data() {
        return {
          sid: '{$sid}',
          tid: "",
          teacher: {}
        }
      },
      mounted() {
        // 初始化富文本编辑器
        var ue = UE.getEditor('contents-box');
        //获取url中"?"符后的字串
        var url = location.search;
        var theRequest = new Object();
        if (url.indexOf("?") != -1)
        {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++)
            {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        this.tid = theRequest.tid;
        this.requestData();
      },
      methods: {
        requestData() {
          let that = this;
          axios.post('/dboard/teacher/infoData', {tid: this.tid},{headers: {'X-Requested-with':'XMLHttpRequest'}}).then(res => {
            // console.log(res);
            if(res.data.Code == 0){
              that.teacher = res.data.Data.teacher;
              $("#contents-box").val(res.data.Data.teacher.description);
              $("#teacher_info_pic").val(res.data.Data.teacher.avatar+",");
              if($("#teacher_info_pic").val().length != 0){
                show_photo('#teacher_info_pic');
              }
              // 初始化富文本编辑器
              var ue = UE.getEditor('contents-box');
              var str = $("#contents-box").val();
              ue.ready(function() {
                ue.setContent(str,false);
              });
            }else{
              alert(res.data.Msg)
            }
          }).catch(err => {
            console.log(err);
          })
        },
        // 提交
        doSubmit(){
          var that = this;
          var param = {
            sid: that.sid,
            tid: that.tid,
            name: that.teacher.name,
            phone: that.teacher.tel,
            ordernum: that.teacher.ordernum,
            title: that.teacher.title,
            description: UE.getEditor('contents-box').getContent(),
          }
          var teacherStr = $('#teacher_info_pic').val();
          var teacherArray = teacherStr.split(",");
          teacherArray.splice(teacherArray.length-1, 1);
          if(teacherArray.length>0) { param.avatar = teacherArray[0] };
          if(teacherArray.length>1) { alert('教师头像最多上传1张');return false}

          axios.post('/dboard/teacher/editTeacherinfo', param,{headers: {'X-Requested-with':'XMLHttpRequest'}}).then(res => {
            // console.log(res);
            if(res.data.Code == 0){
              //请求成功
              alert(res.data.Msg);
              // window.location.href = '/index/index/get_daily_report_list';
              window.location.href = '/dboard/teacher/lists';
            }else{
              alert(res.data.Msg)
            }
          }).catch(err => {
            console.log(err);
          })
        }
      }
    })
  </script>
